package dbinit;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.Set;

import util.database.init.DbUtil;
import core.address.model.continent.Continent;
import core.address.model.country.Country;
import core.address.model.region.Region;
import core.address.model.state.State;
import core.product.model.RatingAndReview;

public class DbInit {

	public static void main(String[] args) {
	
		/*
		 * recreate database advprop
		 */
		DbUtil.reCreateDb("advprop");
		/*
		 * crate continent Asia
		 */
		Long continentId = InitContinent.doinit("Asia");
		Continent conti = InitContinent.getContinentByUuid(continentId);
		/**
		 * class Country table country
		 *  Long doinit(String countryName)
		 */
		Long countryId = InitCountry.doinit("INDIA",conti,"IN");
		Country con = InitCountry.getCountryByUuid(countryId);
		/**
		 *  class State table state
		 *  Long doinit(Long countryId,String stateName)
		 */
		Long stateId = InitState.createOrGetUuidByName(con,"UP",conti,"UP");
		State s = InitState.getStateByUuid(stateId);
		/*
		 * create instance of region
		 * 
		 */
		Long regionId = InitRegion.doinit("Phoenix Area", s, con , conti);
		Region r = InitRegion.getRegionByName("Phoenix Area");
		/** 
		 * class City table city
		 *  Long doinit(Long stateId , String cityName)
		 */
		Long cityId1 = InitCity.doinit(s,r,con,conti,"Noida");
		Long cityId2 = InitCity.doinit(s,r,con,conti,"SPN");
		/**
		 * class AddressType table addresstype
		 * Long doinit(String addressType)
		 */
		Long addresstypeId = InitAddressType.doinit("Current");
		Long addresstypeId2 = InitAddressType.doinit("Permanent");
		/**
		 * class BasicAddress table basicaddress
		 * Long doinit(Long addressTypeId,String addressLine1 , String addressLine2 ,String phone,String mobile,String email, String fax, String homepage, String postalcode, String phonebusiness, String companyname,String firstname,String secondname,String lastname,String title ,Long countryId,Long stateId,Long cityId)
		 */
		Long currentAddressId = InitBasicAddress.doinit(addresstypeId,"Sec 56","Noida","970089898","0120989890","a@a.com","43434","www.google.com","24323232","3232323","ebsi","vineet","kumar","saxena","Mr",countryId,stateId,cityId1);
	    Long permanentAddressId = InitBasicAddress.doinit(addresstypeId2,"Tlh 56","SPN","970089898","0120989890","b@a.com","43434","www.google.com","24323232","3232323","ebsi","vineet","kumar","saxena","Mr",countryId,stateId,cityId2);
		/**
		 * class BasicRoleRules table basicrolerules
		 * 
		 */
		Long basicrolerulesId = InitBasicRoleRules.doinit("Edit Own Product","He can edit his product","edit_his_product");
		Long basicrolerulesId2 = InitBasicRoleRules.doinit("Edit All Product","He can edit All product","product_manager");
		Set <Long> basicRoleRules = new HashSet<Long>();
		Set <Long> basicRoleRules2 = new HashSet<Long>();
		basicRoleRules2.add(basicrolerulesId);
		basicRoleRules.add(basicrolerulesId);
		basicRoleRules.add(basicrolerulesId2);
		/**
		 * class BasicRoles table basicroles
		 * Long doinit(Long organizationId,String roleName)
		 */
		Set <Long> basicRoles = new HashSet<Long>();
		Long basicroleId = InitBasicRoles.doinit("Admin",basicRoleRules);
		Long basicroleId2 = InitBasicRoles.doinit("Owner",basicRoleRules2);
		basicRoles.add(basicroleId);
		basicRoles.add(basicroleId2);
		//-------------------------------------------
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		java.util.Date utilDOB = null ;
		try {
			utilDOB = formatter.parse(12 + "/" + 12 + "/" + 1983);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		java.util.Date utilJoinD = null;
		try {
			utilJoinD = formatter.parse(01 + "/" + 01 + "/" + 2010);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		java.sql.Date dob = new java.sql.Date(utilDOB.getTime());
		java.sql.Date aniverary = dob ;
		java.sql.Date joinD = new java.sql.Date(utilJoinD.getTime());
		
		// Getting Today Date
		java.util.Date td = new java.util.Date();
		java.sql.Date tsd = new java.sql.Date(td.getTime());
		/**
		 * Class BasicProfile table basicProfile
          * Long doinit(Date anniversary,Date birthdaydate,String companyname,String firstname,String gender,int usertype,String lastname,String nickname,String secondname,String title,String businesspartnerno,String creationdate,Boolean status,String emailId,Long currentAddressId,Long permanentAddressId,Set<Long> basicRoles)
		 */
         Long basicprofileId =  InitBasicProfile.doinit(aniverary,dob,"ebsi","Vineet","Male",4,"saxena","vineet","kumar","Mr","BPN01",tsd,true,"vineet.saxena10@gmail.com",currentAddressId,permanentAddressId,basicRoles);
         Long basicprofileId2 =  InitBasicProfile.doinit(aniverary,dob,"ebsi","jamil","Male",3,"saxena","jamil","kumar","Mr","BPN02",tsd,true,"mnnit.jamil@gmail.com",currentAddressId,permanentAddressId,basicRoles);
		/**
		 * this class sets attribute values to the basic profile entity
		 *  Long doinit(String name,String stringValue,int intValue ,float floatValue,java.sql.Date dateValue ,String dataType, Long basicprofileId)
		 *  datatype could be "string , int , float , date"
		 */
		Long basicprofileavId = InitBasicProfileAv.doinit("custom","value","string",basicprofileId);
		/*
		 * Long doinit(String question)
		 */
		Long securityQId = InitSecurityQuestion.doinit("Waht is your pet's name ?");
		/**
		 * this class sets username and password to the user
		 * class BasicCredential table basiccredential
		 * Long doinit(String userId,String password,Long basicprofileId,int disabledflag,String passwordreminder,String reminderemail,Long securityquestion,String answer,int failurecount)
		 * disabledflag :- 1 for enabled 0 for disabled
		 */
		Long basiccredentialId = InitBasicCredential.doinit("vineet.saxena10@gmail.com","adv",basicprofileId,1,"no","no",securityQId,"HAPPY",0);
		/*
		 * craating product type
		 * class ProductType table producttype
		 * Long doinit(String productType)
		 */
		Long productTypeId = InitProductType.doinit("Guest House");
		Long productTypeId2 = InitProductType.doinit("Hotel");
		/*
		 * create price type
		 * class PriceType table pricetype
		 * price type could be Sale Price  , Rent Per Month , Rent Per Day , Rent Per Year
		 * 
		 */
		Long salePrice = InitPriceType.doinit("Sale Price");
		Long rentPricePM = InitPriceType.doinit("Rent Per Month");
		Long rentPricePD = InitPriceType.doinit("Rent Per Day");
		Long rentPricePY = InitPriceType.doinit("Rent Per Year");
		/*
		 * create the object of product ...
		 * class Product table product
		 * Long doinit(String sku, String name, Long owner, String imagePath, String thumbnail,ProductType productType,Set<RatingAndReview> ratingAndReview, boolean avalable, boolean enabled)
		 */
		Long productId = InitProduct.doinit("Hotel01","Tiwari Hotel", "imageNotFound", "thumbNotFound", productTypeId2,null ,true, true) ;
	    Long productId2 = InitProduct.doinit("guest_house01","jamil guest House" , "imageNotFound", "thumbNotFound", productTypeId,null ,true, true) ;
	    
	    /*
	     * create price set object for product
	     * class Price table price
	     * Long doinit(float price,float specialprice,Date startdate,Date enddate,String comment)
	     */
	    Long priceId1 = InitPrice.doinit(10.0f,0f, null, null,salePrice,"no discount",productId);
	    Long priceId2 = InitPrice.doinit(2.0f,0f, null, null,rentPricePD,"no discount",productId);
	    Set <Long> priceSet1 = new HashSet<Long>();
	    priceSet1.add(priceId1);
	    priceSet1.add(priceId2);
	    
	    Long priceId3 = InitPrice.doinit(20.0f,0f, null, null,salePrice,"no discount",productId2);
	    Long priceId4 = InitPrice.doinit(5.0f,0f, null, null,rentPricePM,"no discount",productId2);
	    Set <Long> priceSet2 = new HashSet<Long>();
	    priceSet2.add(priceId3);
	    priceSet2.add(priceId4);
	    
	    InitProduct.updateProductPrice(InitProduct.getProductByUuid(productId), priceSet1.iterator());
	    InitProduct.updateProductPrice(InitProduct.getProductByUuid(productId2), priceSet2.iterator());
	    
	    /*
	     * setting up product Owner
	     * class ProductOwner table productowner
	     * Long doinit(Long productId , Long ownerId)
	     */
	    Long productOwnerId = InitProductOwner.doinit(productId, basicprofileId);
	    Long productOwnerId2 = InitProductOwner.doinit(productId, basicprofileId2);
	    /*
		 * craating the object of rating and review
		 * class RatingAndReview table rating and review
		 *  Long doinit(String review, int rating, Long reviewer)
		 */
		Long ratingAndReviewId = InitRatingAndReview.doinit("This is cool place.", 3 , basicprofileId, productId);
		Long ratingAndReviewId2 = InitRatingAndReview.doinit("This is cool place for honeymoon ;).", 5 , basicprofileId2,productId2);
		Long ratingAndReviewId3 = InitRatingAndReview.doinit("This is nice.", 4 , basicprofileId2 ,productId);
		Long ratingAndReviewId4 = InitRatingAndReview.doinit("This is cool place for family too", 4 , basicprofileId,productId2);
	    Set<RatingAndReview> ratingAndReview = new HashSet<RatingAndReview>();
	    Set<RatingAndReview> ratingAndReview2 = new HashSet<RatingAndReview>();
	    ratingAndReview.add(InitRatingAndReview.getRatingAndReviewByUuid(ratingAndReviewId));
	    ratingAndReview.add(InitRatingAndReview.getRatingAndReviewByUuid(ratingAndReviewId2));
	    ratingAndReview2.add(InitRatingAndReview.getRatingAndReviewByUuid(ratingAndReviewId3));
		
	}

}
